// pages/user/user.js
const { getLogin } = require("../api/index")
Page({
  data: {
    userInfo:{},
    list:[
      {
          text:"前端",
          icon:"like",
          color:"#ff0000"
      },
      {
          text:"Python",
          icon:"star",
          color:"#2a83fe"
      },
      {
          text:"Java",
          icon:"fire",
          color:"#fd6012"
      },
      {
          text:"大数据",
          icon:"gem",
          color:"#fd4d72"
      },
      {
          text:"人工智能",
          icon:"gift",
          color:"#00b478"
      },
      {
          text:"算法",
          icon:"shop",
          color:"#fe391f"
      }
  ]

  },

  onLoad(options) {
    if(wx.getStorageSync('userInfo')){
      this.setData({
        userInfo:wx.getStorageSync('userInfo')
      })
    }
  },
  getUserProfile(){
    wx.getUserProfile({
      desc: '展示用户信息',
      success:res =>{
        this.setData({
          userInfo:res.userInfo,
          
        })
        wx.setStorageSync('userInfo', res.userInfo)
        this.loginHandle()
      },
      fail(err){
        console.log(err);
      },
      complete(){
        console.log("获取完成")
      }
    })
  },
  loginHandle(){
    wx.login({
      success: (response) => {
        //发送code给接口
        getLogin({code:response.code}).then(res =>{
          console.log(res.data)
          wx.setStorageSync('loginID', res.data.data)
        })
        // console.log(response.code)
      },
      fail(err){
        console.log(err);
      }
    })
  }
  
})